/**
 * jgamebox
 *
 * outlook@China software studio
 * Copyright (c) 2008-2010. All Rights Reserved.
 * http://www.outlook.com
 */

package org.outlook.jgamebox.api;

import org.outlook.common.measure.Direction;
import org.outlook.common.measure.Position;
import org.outlook.common.measure.Speed;
import org.outlook.common.measure.Volume;

/**
 * function:
 * @author Watson email: watson.wu@hotmail.com
 * @date 2011
 */
public class Instance implements Substance {
	
	//measure
	Volume volume;
	Speed speed;	
	Position position;
	Direction direction = Direction.UP;

	int life;//number of lift, -1 means could not be over, life will decrease by hitting.

	public Instance() {
		this(new Volume(), new Speed(), new Position(), Direction.UP, 0);
	}

	public Instance(Volume volume, Speed speed, Position position,
			Direction direction, int life) {
		super();
		this.volume = volume;
		this.speed = speed;
		this.position = position;
		this.direction = direction;
		this.life = life;
	}

	@Override
	public Volume getVolume() {
		return volume;
	}

	@Override
	public void setVolume(Volume volume) {
		this.volume = volume;
	}

	@Override
	public Speed getSpeed() {
		return speed;
	}

	@Override
	public void setSpeed(Speed speed) {
		this.speed = speed;
	}

	@Override
	public Position getPosition() {
		return position;
	}

	@Override
	public void setPosition(Position position) {
		this.position = position;
	}

	@Override
	public Direction getDirection() {
		return direction;
	}

	@Override
	public void setDirection(Direction direction) {
		this.direction = direction;
	}
	
	@Override
	public int getWidth() {
		if(volume == null)
			return 0;
		else
			return volume.getWeight();
	}

	@Override
	public int getHeight() {
		if(volume == null)
			return 0;
		else
			return volume.getHeight();
	}
	
	@Override
	public int getThick() {
		if(volume == null)
			return 0;
		else
			return volume.getThick();
	}

	@Override
	public int getPositionX() {
		if(position == null)
			return 0;
		else
			return position.getX();
	}

	@Override
	public int getPositionY() {
		if(position == null)
			return 0;
		else
			return position.getY();
	}

	@Override
	public int getPositionZ() {
		if(position == null)
			return 0;
		else
			return position.getZ();
	}

	@Override
	public int getSpeedX() {
		if(speed == null)
			return 0;
		else
			return speed.getX();
	}

	@Override
	public int getSpeedY() {
		if(speed == null)
			return 0;
		else
			return speed.getY();
	}

	@Override
	public int getSpeedZ() {
		if(speed == null)
			return 0;
		else
			return speed.getZ();
	}

	@Override
	public int getLife() {
		return life;
	}

	@Override
	public void setLife(int life) {
		this.life = life;
	}
	
	public boolean isAlive() {
		return life != 0;
	}

}
